'use strict';

const Service = require('egg').Service;

class HomeService extends Service {
  async carousel() {
    const { ctx, app } = this;
    const QUERY_STR = '*';
    const sql = `select ${QUERY_STR} from carousel`;
    try {
      const result = await app.mysql.query(sql);
      return result;
    } catch (error) {
      console.log(error);
      return null;
    }
  }
  async addCarousel(carousel_id, imgPath, describes, id, create_date, modify_date, img_path) {
    const { ctx, app } = this;
    try {
      const result = await app.mysql.insert('carousel', { carousel_id, imgPath, describes, id, create_date, modify_date, img_path });
      return result;
    } catch (error) {
      console.log(error);
      return null;
    }
  }
  async editCarousel(carousel_id, describes) {
    const { ctx, app } = this;
    try {
      const result = await app.mysql.update('carousel', { describes }, {
        where: {
          carousel_id,
        },
      });
      return result;
    } catch (error) {
      console.log(error);
      return null;
    }
  }
  async deleteCarousel(id) {
    const { ctx, app } = this;
    try {
      const result = await app.mysql.delete('carousel', { id });
      console.log(result);
      return result;
    } catch (error) {
      console.log(error);
      return null;

    }
  }
}
module.exports = HomeService;
